package action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSON;

import dao.UserDao;
import entity.User;

/**
 * 校验Email地址是否重复
 * true:Email地址重复
 * false：Email地址不重复
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class CheckEmailServlet extends HttpServlet{
	private static Logger log = Logger.getLogger(CheckEmailServlet.class);
	
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String email = request.getParameter("email");
		UserDao dao = new UserDao();
		boolean result = false;
		try {
			User user = dao.queryUserByEmail(email);
			result = user == null ? false : true;
		} catch (Exception e) {
			log.error("error occurs while checking email -- > " + e);
		}
		PrintWriter out = response.getWriter();
		out.write(JSON.toJSONString(result));
	}
}
